// pages/ebooklist/ebooklist.js
import http from '../../utils/request'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        reslist:[],
        shareImageurl:'',
        shareTitle:'',
        shareId:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getSpeciallist(options.id)
        this.setData({shareTitle:decodeURIComponent(options.title),shareId:options.id})
        
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function (options) {
        wx.setNavigationBarTitle({
            title:decodeURIComponent(this.data.shareTitle),
          })
        console.info(this.data.shareTitle)
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        wx.showShareMenu({
            withShareTicket:true,
            menus:['shareAppMessage','shareTimeline']
          })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        // console.info(this.data.shareImageurl)
        // return {
        //     title:this.data.shareTitle,
        //     path:'',
        //     imageUrl:this.data.shareImageurl
        //   };
    },
    /**
     * 用户点击右上角分享朋友圈
     */
    onShareTimeline: function () {
        return {
          title:this.data.shareTitle,
          query:`id=${this.data.shareId}&title=${this.data.shareTitle}`,
          imageUrl:this.data.shareImageurl
        }
      },
    resourcelist(e){
        let id = e.currentTarget.dataset.id
        let link = `https://www.bslmedu.com/wap/#/pages/ebook/ebookdetail?id=${id}`
        // console.info(link)
        // return false
        wx.navigateTo({
            url: '/pages/webview/webview?url='+encodeURIComponent(link),
        })
    },
    //专题类型
    async getSpeciallist(id){
        var that = this;
        var options={
           url:'/getEbookResourcebundleById',
            method:'POST',
            data:{ebookresourcebundleId:id},
            header:{"content-type":"application/json;charset=UTF-8"}
        }
        let res = await http(options)
        if(res.data.code==0){
            that.setData({
                reslist: res.data.obj,
                shareImageurl:'https://'+res.data.obj[0].ebookIconOSS
            });
        }
    },
})